/*
 *
 *  * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 *
 *
 */

package com.iwindplus.base.kafka.domain.property;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

/**
 * kafka配置.
 *
 * @author zengdegui
 * @since 2020/4/24
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@ConfigurationProperties(prefix = "spring.kafka")
public class KafkaProperty {

    /**
     * 是否开启.
     */
    @Builder.Default
    private Boolean enabled = true;

    /**
     * 是否开启动态注册主题.
     */
    @Builder.Default
    private Boolean enabledDynamicRegister = true;

    /**
     * 配置集合.
     */
    @Builder.Default
    @NestedConfigurationProperty
    private List<Config> configs = new ArrayList<>(10);

    /**
     * kafka配置对象.
     *
     * @author zengdegui
     * @since 2020/4/24
     */
    @Data
    @SuperBuilder
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Config {

        /**
         * 消费组（可选）
         */
        private String groupId;

        /**
         * 主题（必填）.
         */
        private String topicName;

        /**
         * 分区数量（Broker默认配置项）.
         */
        @Builder.Default
        private Integer numPartitions = -1;

        /**
         * 副本数量（Broker默认配置项）.
         */
        @Builder.Default
        private Short replicationFactor = -1;

        /**
         * 其他参数（可选）.
         */
        private Map<String, String> arguments;
    }
}
